﻿Shader "Dan/2D/Stars2D"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"
            #include "../ShaderLibs/Feature.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                float4 ret = float4(0,0,0,1);
                float2 uv =i.uv;
                float SIZE =0.5;
                float time =_Time.y;
                uv*=10;
                float2 gridID = floor(uv);
                uv = frac(uv); 
                float2 hash2 =Hash22(gridID);

               
                float deg =((step(hash2.y,0.5)*2-1)*0.5)+hash2.x*_PI2;
                float2 offset =float2(cos(deg),sin(deg))*0.35;
                
                float2 mask =saturate(sin(uv+time*10)/20);
                mask =saturate(1-pow(mask,0.5));
                
                float sizeHash =sin(hash2+_Time.y*20);
                float sizeScale =sin(time+hash2*_PI2)*0.5+0.5;
                sizeScale =saturate(lerp(0.1,0.5,sizeScale));

                float size =0.2*sizeScale;
           

                float stars = DrawCircle02(uv,offset,size,float2(0,0.1));


                return  stars;
            }
            ENDCG
        }
    }
}
